package org.ddd.specification.test;

import junit.framework.Assert;

import org.ddd.specification.Specification;

/**
 * A set of specification based assertions. Messages are only displayed when an assert fails.
 * 
 * @author Jeroen van Schagen
 * @since 22-02-2011
 */
public class SpecificationAssert {

    /**
     * Assert that our candidate satisfies the provided specification.
     * @param candidate candidate that should be asserted
     * @param specification specification that should be satisfied
     * @param <T> type of candidate being checked
     */
    public static <T> void assertThat(T candidate, Specification<? super T> specification) {
        assertThat("", candidate, specification);
    }

    /**
     * Assert that our candidate satisfies the provided specification.
     * @param <T> type of candidate being checked
     * @param message message to provide when assertion fails
     * @param candidate candidate that should be asserted
     * @param specification specification that should be satisfied
     */
    public static <T> void assertThat(String message, T candidate, Specification<? super T> specification) {
        boolean satisfied = specification != null ? specification.isSatisfiedBy(candidate) : false;
        Assert.assertTrue(message, satisfied);
    }

}
